<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="9" :sm="9">
            <a-form-item>
              <j-input placeholder="请输入vin码/手机号码/身份证号" v-model="queryParam.key"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="chaxun" icon="search">查询</a-button>
              <!-- <a-button type="primary" @click="changeList(1)" style="margin-left: 10px;">待交付</a-button>
              <a-button type="primary" @click="changeList(2)" style="margin-left: 10px;">已交付</a-button> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="index"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 1500 }"
      >
        <span slot="action" slot-scope="text, record">
          <a-button
            type="primary"
            @click="gotoprint(record)"
            style="margin-right: 10px;"
            v-if="record.deliverType == 2"
          >打印</a-button>
          <a-button
            type="primary"
            @click="getInfo(record)  "
            style="margin-right: 10px;"
            v-if="record.deliverType == 1"
          >填写交付单</a-button>
          <!-- <a-button @click="showModal">作废</a-button>
          <a-modal v-model="visible2" title="作废提示" @ok="deleteId(record)">
            <p>是否对该条记录进行作废？作废后将无法恢复！</p>
          </a-modal>-->
        </span>
        <span
          slot="filterDepositAttribute"
          slot-scope="carStatus"
        >{{ carStatus | filterDepositAttribute(carStatus) }}</span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <send-out-model-vue ref="modalForm" @ok="modalFormOk"></send-out-model-vue>
    <send-out-print-model ref="modalForm2" @ok="modalFormOk"></send-out-print-model>
  </a-card>
</template>

<script>
import SendOutModelVue from './SendOutModel.vue'
import SendOutPrintModel from './SendOutPrintModel.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import moment from 'moment'
import { USER_INFO } from '@/store/mutation-types'
import Vue from 'vue'
import { getAction, httpAction } from '@/api/manage'
export default {
  name: 'VehicleRegister',
  mixins: [JeecgListMixin],
  components: {
    SendOutModelVue,
    SendOutPrintModel,
    JInput,
    moment,
  },
  data() {
    return {
      description: 'cxm-订单管理页面',
      visible: false,
      visible2: false,
      // 表头
      loading: '',
      columns: [
        {
          title: '订单号',
          align: 'center',
          dataIndex: 'orderId',
        },
        {
          title: '车架号',
          align: 'center',
          dataIndex: 'vin',
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerName',
        },
        {
          title: '手机号',
          align: 'center',
          dataIndex: 'contactPhone',
        },
        {
          title: '车辆品牌车型',
          align: 'center',
          dataIndex: 'brand',

        },
        /* {
          title: '销售状态',
          align: 'center',
          dataIndex: 'carStatus',
          scopedSlots: {
            customRender: 'filterDepositAttribute',
          },
        }, */
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: '240',
          fixed: 'right',
          scopedSlots: {
            customRender: 'action',
          },
        },
      ],

      url: {
        list: '/sale/cxmSaleDeliverInfo/list',
        querySendOut: '/sale/cxmSaleCarInfo/queryById',
        //delete: '/sale/cxmSaleCarInfo/delete',//通过id删除
        //deleteBatch: '/sale/cxmSaleCarInfo/deleteBatch',//批量删除

        exportXlsUrl: 'cxm/cxmSaleDeliverInfo/exportXls',//导入
        importExcelUrl: 'cxm/cxmSaleDeliverInfo/importExcel',//导出
      },
      showButton: true,
      deliverType: 1,
      
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    showModal() {
      this.visible2 = true;
    },
    getInfo(record) {
      this.$refs.modalForm.edit(record)
    },
    gotoprint(record) {
      this.$refs.modalForm2.edit(record)
    },
    deleteId(record) {
      console.log(record);
      let httpurl = this.url.delete + '?id=' + record.id;
      let formData = {}
      let method = 'post';

      httpAction(httpurl, formData, method).then((res) => {
        console.log(res);
        if (res.success) {
          console.log(res.result);
          this.visible2 = false;
          this.loadData();
        }
      })
    },
    /* changeList(params) {
      this.url.list = '/sale/cxmSaleDeliverInfo/list?deliverType=' + params;
      if (params == 1) {
        this.showButton = true;
        this.deliverType = 1;
      } else if (params == 2) {
        this.showButton = false;
        this.deliverType = 2;
      }
      this.loadData()
    }, */
    chaxun() {
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      const that = this;
      getAction('/sale/cxmSaleDeliverInfo/list?deliverType=' + that.deliverType, params).then((res) => {
        console.log(res)
        if (res.success) {
          that.dataSource = res.result.records;
          console.log(that.dataSource);
          that.ipagination.total = res.result.total;
        }
        if (res.code === 510) {
          that.$message.warning(res.message)
        }
        that.loading = false;
      })
    },
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      switch (depositAttribute) {
        case 1:
          return "在库"
          break;
        case 2:
          return "已售"
          break;
        case 3:
          return "返厂"
          break;
      }
    }
  },
}
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
